﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<link href="tablecloth/tablecloth.css" rel="stylesheet" type="text/css" media="screen" />
<script type="text/javascript" src="tablecloth/tablecloth.js"></script>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body>

<?php
//Teamwahl


include("inc/joomlaInt.php");
include("inc/inc_configuration.php");
include("inc/inc_sperre.php");

if ($jUser==0)
{
	echo "Bitte zuerst einloggen!";
}
else
{	
	if ($faktiv==1)
	{
		$zeit=time();
		if ($zeit<$fzeit)
		{
			echo "Bitte warte bis ",date("H:i",$fzeit)," Uhr am ",date("d.m.y",$fzeit),".";
			echo "<br><br>
			<center><a href='lima.php' class='button zurueck'>Zurück</a></center>";
			break;
		}
	}

	//$teamId=$_SESSION["teamId"];

	$af_t_vh="	SELECT l.Id AS leagueId,  t.id AS teamId, t.rating AS rating  
				FROM $tbl_combinations c, $tbl_teams t, $tbl_leagues l, $tbl_season s, $tbl_lt lt 
				WHERE 	c.userID=$jUser AND 
						c.active=1 AND 
						c.teamId=t.id AND
						s.active=1 AND
						l.seasonId=s.id AND
						lt.teamId=t.id AND
						lt.leagueId=l.id AND
						l.type=1"; //vorhandene Teams suchen
	$e_t_vh = mysql_query($af_t_vh);
	$count = mySQL_num_rows($e_t_vh);
	$_SESSION["combicount"]=$count;
	
	$max=$maxrating;
	
	$maxsperre=10;
	
	if (hat_sperre($jUser)==true)
	{
		$maxsperre=$sperremax;
	}
	
	


	if ($count<2)
	{
		if ($count>0)
		{
			$leagueO = mysql_fetch_object($e_t_vh);
			$league = $leagueO->leagueId;
			$rating = $leagueO->rating;
			
			$max=$maxrating-$rating;
			
			$ligaQ = "SELECT l.name AS name, l.id AS id, l.picid FROM $tbl_leagues l, $tbl_season s WHERE l.seasonId=s.id AND s.active=1 AND l.id<>$league AND l.type=1";
		}
		else
		{
			$ligaQ = "SELECT l.name AS name, l.id AS id, l.picid FROM $tbl_leagues l, $tbl_season s WHERE l.seasonId=s.id AND s.active=1 AND l.type=1";
		}
		$ligaQe = mysql_query($ligaQ);
		
		$i=0;
		
		while ($li = mysql_fetch_object($ligaQe))
		{
			if ($i>0)
			{
				echo "<br><br>";
			}
			
			$liga = $li->id;
			$ln = $li->name;
			
			
			$abfrage = "SELECT 	t.name AS name,
								t.id AS id,
								t.rating AS rating
						FROM 	$tbl_teams t, 
								$tbl_lt lt, 
								$tbl_season s,
								$tbl_leagues l
						WHERE 	t.vergeben=0 AND 
								lt.teamid=t.id AND 
								lt.leagueId=l.id AND 
								s.active=1 AND
								l.id=$liga AND
								l.type=1 AND
								t.rating<=$max AND
								t.rating<=$maxsperre
								";
			$ergebnis = mysql_query($abfrage);
			
			$anz=mysql_num_rows($ergebnis);
			
			if ($anz>0)
			{
				//echo"<br><br>";
				
				$q="SELECT lp.path AS path FROM $tbl_leagues l, $tbl_leaguepics lp WHERE l.id=$liga AND l.picId=lp.id";
				$qe=mysql_query($q);
				$qeo=mysql_fetch_object($qe);
				$path=$qeo->path;

				echo "<center><img src='img/leagues/",$path,"' width='",$leaguelogowidth,"' height='",$leaguelogoheight,"' alt='$ln'></center>"; //alt='$l1n'></center>";
				
				echo "<table><thead><tr><th colspan='4'></th></tr></thead>";
				while ($row = mysql_fetch_object($ergebnis))
				{
					$r=$row->rating;
					$r=$r*10;
					$id=$row->id;
					echo "<tr>";
					echo '	<td>	<form action="teamwahl_v.php" method="post">
									<input type="radio" name="team" value="',$row->id,'">
							</td>';
					echo "<td><img src='img/logos/",$id,".png' width='35' height='35' alt=''></td>";
					echo "<td><a href='team_kader.php?team=$id'>",$row->name,"</a></td>";
					echo "<td><img src='img/ratings/",$r,".png' width='125' height='25' alt='",$r,"'></td>";
					echo "</tr>";
				}

				echo "<thead><tr><th colspan='4'></th></tr></thead></table><br><input type='submit' value='Übernehmen' class='button eintragen'></form>";
			}
			
			$i++;
		}
		echo "<br><br>
				<center><a href='lima.php' class='button zurueck'>Zurück</a></center>";
	}
	else
		echo "Sie haben bereits ein Team.";



	//$name=$_POST["nameVerein"];
	//$bewertung=$_POST["bewertung"];

	//$eintrag = "INSERT INTO vereine (name, rating) VALUES ('$name', '$bewertung')";
	//$eintragen = mysql_query($eintrag);
}
?>

</body>
</html>